﻿<UserControl x:Class="nRoute.Samples.Netflix.Views.TitleView" 
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"  
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" 
             xmlns:n="http://nRoute/schemas/2010/xaml"
             xmlns:local_Behaviors="clr-namespace:nRoute.Samples.Netflix.Behaviors"			 
             mc:Ignorable="d"
             d:DesignHeight="600" d:DesignWidth="800">
    
    <UserControl.Resources>
        <n:ValueConverterRelay x:Name="SecondsToTimeConverter" x:Key="SecondsToTimeConverter" />
        <n:ValueConverterRelay x:Name="StripHTMLConverter" x:Key="StripHTMLConverter" />
        <n:ValueConverterRelay x:Name="BoxArtUrlConverter" x:Key="BoxArtUrlConverter"/>
        <n:ValueConverterRelay x:Name="RatingToWidthConverter" x:Key="RatingToWidthConverter"/>
        <n:ValueConverterRelay x:Key="GenreTitlesQueryConverter" />
		<n:ValueConverterRelay x:Key="LanguageTitlesQueryConverter" />
				
        <Storyboard x:Key="OnLoaded1">
        	<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" Storyboard.TargetName="LayoutRoot">
        		<EasingDoubleKeyFrame KeyTime="0:0:1" Value="0">
        			<EasingDoubleKeyFrame.EasingFunction>
        				<CircleEase EasingMode="EaseOut"/>
        			</EasingDoubleKeyFrame.EasingFunction>
        		</EasingDoubleKeyFrame>
        	</DoubleAnimationUsingKeyFrames>
        	<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" Storyboard.TargetName="stackPanel">
        		<EasingDoubleKeyFrame KeyTime="0:0:1.4" Value="0">
        			<EasingDoubleKeyFrame.EasingFunction>
        				<CircleEase EasingMode="EaseOut"/>
        			</EasingDoubleKeyFrame.EasingFunction>
        		</EasingDoubleKeyFrame>
        	</DoubleAnimationUsingKeyFrames>
        </Storyboard>
				
		<DataTemplate x:Key="GenreItemTemplate">
			<TextBlock Text="{Binding Name}" Margin="0,0,0,4" Cursor="Hand" TextWrapping="Wrap" HorizontalAlignment="Left" >
				<i:Interaction.Triggers>
					<i:EventTrigger EventName="MouseLeftButtonUp">							
						<n:NavigateAction HandlerName="ContentContainer" Url="Content/Netflix/Titles/" >
							<n:DependencyParameter Key="MovieQuery" Value="{Binding Converter={StaticResource GenreTitlesQueryConverter}}"/>
							<n:DependencyParameter Key="PageTitle" Value="{Binding Name, StringFormat={}Genre: {0}, ConverterCulture='en-US'}"/>
						</n:NavigateAction>
					</i:EventTrigger>
				</i:Interaction.Triggers>
			</TextBlock>
		</DataTemplate>

		<DataTemplate x:Key="LanguageItemTemplate">		
			<TextBlock Text="{Binding Name}" Margin="0,0,0,4" TextWrapping="Wrap" Cursor="Hand" HorizontalAlignment="Left" >
				<i:Interaction.Triggers>
					<i:EventTrigger EventName="MouseLeftButtonUp">							
						<n:NavigateAction HandlerName="ContentContainer" Url="Content/Netflix/Titles/" >
							<n:DependencyParameter Key="MovieQuery" Value="{Binding  Converter={StaticResource LanguageTitlesQueryConverter}}"/>
							<n:DependencyParameter Key="PageTitle" Value="{Binding Name, StringFormat='Language: \{0\}'}"/>
						</n:NavigateAction>
					</i:EventTrigger>
				</i:Interaction.Triggers>
			</TextBlock>
		</DataTemplate>
		
    </UserControl.Resources>

    <i:Interaction.Behaviors>
        <n:BridgeViewModelBehavior/>
        <n:BridgeValueConverterBehavior ValueConverterRelay="{DynamicResource GenreTitlesQueryConverter}" 
			ConverterSource="{Binding GenreQueryConverter}"/>
        <n:BridgeValueConverterBehavior ValueConverterRelay="{DynamicResource LanguageTitlesQueryConverter}" 
			ConverterSource="{Binding LanguageQueryConverter}"/>
    </i:Interaction.Behaviors>
	
	<UserControl.Triggers>
		<EventTrigger RoutedEvent="FrameworkElement.Loaded">
			<BeginStoryboard Storyboard="{StaticResource OnLoaded1}"/>
		</EventTrigger>
	</UserControl.Triggers>

    <ScrollViewer x:Name="LayoutRoot" Background="White" Padding="0" 
		ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
		ScrollViewer.VerticalScrollBarVisibility="Auto" 
		Style="{StaticResource BorderedScrollViewerStyle}" 
        BorderThickness="0,0,1,0" Margin="0,0,60,55" BorderBrush="#FF81868F"
		DataContext="{Binding MovieTitle}" RenderTransformOrigin="0.5,0.5" >
    	<ScrollViewer.RenderTransform>
    		<TransformGroup>
    			<ScaleTransform/>
    			<SkewTransform/>
    			<RotateTransform/>
    			<TranslateTransform X="50"/>
    		</TransformGroup>
    	</ScrollViewer.RenderTransform>
        <Grid Margin="20,0,20,0">
        	<Grid.RowDefinitions>
        		<RowDefinition Height="Auto"/>
        		<RowDefinition Height="Auto"/>
        		<RowDefinition Height="Auto"/>
        	</Grid.RowDefinitions>
            <StackPanel x:Name="stackPanel" RenderTransformOrigin="0.5,0.5">
            	<StackPanel.RenderTransform>
            		<TransformGroup>
            			<ScaleTransform/>
            			<SkewTransform/>
            			<RotateTransform/>
            			<TranslateTransform X="50"/>
            		</TransformGroup>
            	</StackPanel.RenderTransform>
        		<TextBlock FontFamily="Segoe UI Light" FontSize="42.667" TextWrapping="Wrap" 
        			VerticalAlignment="Top" Margin="0,-8,0,0"><Run Text="{Binding Name}" />
        			<Run Text="{Binding ReleaseYear, StringFormat='({0})'}" /></TextBlock>
        		<TextBlock TextWrapping="Wrap" Foreground="Black" HorizontalAlignment="Left" Cursor="Hand" 
        			FontSize="13.333" FontFamily="Segoe UI Light" Margin="0,0,0,30"><i:Interaction.Triggers>
        				<i:EventTrigger EventName="MouseLeftButtonUp">
        					<n:NavigateAction Url="Content/Rating/" HandlerName="PopupContainer"/>
        				</i:EventTrigger>
        			</i:Interaction.Triggers><Run Text="{Binding Rating, FallbackValue=No Rating Info |, StringFormat=Rated \{0\} |}" /><Run Text=" "/><Run Text=" "/><Run Text="{Binding Runtime, Converter={StaticResource SecondsToTimeConverter}, FallbackValue=Unknown Runtime |, StringFormat=\{0\} |}" /><Run Text=" "/><Run Text=" "/><Run Text="{Binding Type}" /></TextBlock>
        	</StackPanel>
            <Border HorizontalAlignment="Left" Height="300" MinWidth="220" MinHeight="300" BorderBrush="White"
            	VerticalAlignment="Top" Width="220" BorderThickness="8" Background="#FFFDFDFD" d:LayoutOverrides="HorizontalAlignment" Grid.Row="1">
                <Border.Effect>
                    <DropShadowEffect Color="#FF7A7A7A" ShadowDepth="0" BlurRadius="8"/>
                </Border.Effect>
                
                <Image Source="{Binding BoxArt, Converter={StaticResource BoxArtUrlConverter}, FallbackValue=/Resources/PlaceHolder.png}" 
            		Stretch="Fill"/>
            </Border>
        	<StackPanel Margin="240,0,0,0" Orientation="Vertical" VerticalAlignment="Top" Grid.Row="1">
               
        		<TextBlock Text="Synopsis" Foreground="#FF3B3B3B" HorizontalAlignment="Left" TextOptions.TextHintingMode="Animated" FontWeight="Bold" FontSize="12.667"/>
        		<TextBlock Text="{Binding Synopsis, Converter={StaticResource StripHTMLConverter}}" 
        			TextWrapping="Wrap" LineHeight="26" FontSize="13.333" Padding="0,0,20,0" Margin="0,10,0,0"/>
               
        		<TextBlock HorizontalAlignment="Left" FontSize="13.333"><Run Text="{Binding Series}" /><Run Text=" "/>
                    <Run Text="{Binding Season, StringFormat='(Season {0})', TargetNullValue=''}" /></TextBlock>

        		<TextBlock Margin="0,20,0,5" Foreground="#FF3B3B3B" HorizontalAlignment="Left" TextOptions.TextHintingMode="Animated" FontWeight="Bold" FontSize="12.667"><Run Text="Average Rating"/><Run Text=" "/><Run Text="{Binding AverageRating, FallbackValue=--}" FontWeight="Bold"/><Run Text=" "/><Run Text="/ 5" /></TextBlock>
        		<Canvas Height="20" Width="100" HorizontalAlignment="Left">
        			<Image Width="100" Height="20" Source="/nNetflix;component/Resources/EmptyStars.png" Stretch="None"/>
        			<Image Width="{Binding AverageRating, Converter={StaticResource RatingToWidthConverter}}" 
        				Height="20" Source="/nNetflix;component/Resources/FullStars.png" Stretch="None"/>
        		</Canvas>
        	</StackPanel>
        	<WrapPanel Grid.Row="2" Margin="0,0,0,10">
        		<StackPanel MinWidth="200" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="0,0,8,0">
        			<TextBlock Text="Director(s)" Foreground="#FF3B3B3B" HorizontalAlignment="Left" TextOptions.TextHintingMode="Animated" FontWeight="Bold" FontSize="12.667" Margin="0,20,0,0"/>
        			<ItemsControl ItemsSource="{Binding Directors}" ItemTemplate="{StaticResource PersonLinkTemplate}" Margin="0,10,-234,0" FontSize="13.333"/>
				</StackPanel>
				<StackPanel MinWidth="200" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="0,0,8,0">
        			<TextBlock Text="Cast" Foreground="#FF3B3B3B" HorizontalAlignment="Left" TextOptions.TextHintingMode="Animated" FontWeight="Bold" FontSize="12.667" Margin="0,20,0,0"/>
        			<ItemsControl ItemsSource="{Binding Cast}" ItemTemplate="{StaticResource PersonLinkTemplate}" Margin="0,10,-234,0" FontSize="13.333"/>
				</StackPanel>
				<StackPanel MinWidth="200" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="0,0,8,0">
        			<TextBlock Text="Genre(s)" Foreground="#FF3B3B3B" TextOptions.TextHintingMode="Animated" FontWeight="Bold" FontSize="12.667" Margin="0,20,0,0"/>
        			<ItemsControl ItemsSource="{Binding Genres}" ItemTemplate="{StaticResource GenreItemTemplate}" FontSize="13.333" Margin="0,10,0,0"/>
				</StackPanel>
				<StackPanel MinWidth="200" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="0,0,8,0">
        			<TextBlock Text="Language(s)" Foreground="#FF3B3B3B" TextOptions.TextHintingMode="Animated" FontWeight="Bold" FontSize="12.667" Margin="0,20,0,0"/>
        			<ItemsControl ItemsSource="{Binding Languages}" ItemTemplate="{StaticResource LanguageItemTemplate}" FontSize="13.333" Margin="0,10,0,0"/>
				</StackPanel>
        	</WrapPanel>

        </Grid>
    </ScrollViewer>

</UserControl>

